﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RestaurateurConsole
{
    public partial class NewAccountDetails : Form
    {
        private bool cancelled = false;
        public NewAccountDetails()
        {
            InitializeComponent();
            Label userLabel = new Label();
            userLabel.Text = "Account name";
            Label phoneLabel = new Label();
            phoneLabel.Text = "Phone number";
            Button okay = new Button();
            okay.Text = "OK";
            this.AcceptButton = okay;
            Button cancel = new Button();
            cancel.Text = "Cancel";
            this.CancelButton = cancel;

            okay.Click += new EventHandler(okay_Click);
            cancel.Click += new EventHandler(cancel_Click);

            tableLayoutPanel1.Controls.Add(userLabel);
            tableLayoutPanel1.Controls.Add(new TextBox());
            tableLayoutPanel1.Controls.Add(phoneLabel);
            tableLayoutPanel1.Controls.Add(new TextBox());
            tableLayoutPanel1.Controls.Add(new Label());
            tableLayoutPanel1.Controls.Add(new Label());

            okay.Width = userLabel.Width;
            cancel.Width = tableLayoutPanel1.Controls[1].Width;
            tableLayoutPanel1.Controls.Add(okay);
            tableLayoutPanel1.Controls.Add(cancel);

        }

        void cancel_Click(object sender, EventArgs e)
        {
            Cancel();
        }

        void okay_Click(object sender, EventArgs e)
        {
            Okay();
        }

        private void Okay()
        {
            if ((tableLayoutPanel1.Controls[1] as TextBox).Text == "")
            {
                MessageBox.Show("Please enter the name of the account");
                return;
            }
            this.Close();
        }

        private void Cancel()
        {
            cancelled = true;
            this.Close();
        }

        public Boolean IsCancelled
        {
            get
            {
                return cancelled;
            }
        }

        public string AccountName
        {
            get
            {
                return (tableLayoutPanel1.Controls[1] as TextBox).Text;
            }
            set
            {
                (tableLayoutPanel1.Controls[1] as TextBox).Text = value;
            }
        }

        public string Phone
        {
            get
            {
                return (tableLayoutPanel1.Controls[3] as TextBox).Text;
            }
            set
            {
                (tableLayoutPanel1.Controls[3] as TextBox).Text = value;
            }
        }
    }
}
